<?php
class Company extends AppModel {
	var $name = 'Company';
	var $useTable = 'company_info';
	
	var $primaryKey = 'id';
	var $displayField = 'name';
	
	var $belongsTo = array('SysParams' =>  
                            array('className'  => 'SysParams', 
                                  'conditions' => "\"SysParams\".deleted is null",  
                                  'order'      => '',  
                                  'foreignKey' => 'pwd_remain_id'  
                            ) 
                               
                      );
                      
  var $hasMany = array('CompanyArea' =>   
                         array('className'     => 'CompanyArea',   
                               'conditions'    => '"CompanyArea".deleted is null',   
                               'order'         => '',   
                               'limit'         => '',   
                               'foreignKey'    => 'company_id',   
                               'dependent'     => true,   
                               'exclusive'     => false,   
                               'finderQuery'   => ''  
                         )   
                  );                     
	
	/**
	 * @author zhouguoyan
	 * @desc 一般企業アカウント管理 -- 错误信息
	 * */	
	function General_valid($Valid,$params){
		$message = '';
		$message .= $Valid->ErrorMsg($params,'Company/company_name','required');	
		$message .= $Valid->ErrorMsg($params,'Company/company_name','mbmaxlength','300');
		$message .= $Valid->ErrorMsg($params,'Company/company_alias','required');	
		$message .= $Valid->ErrorMsg($params,'Company/company_alias','mbmaxlength','300');		
		$message .= $Valid->ErrorMsg($params,'Company/company_created_year','required');
//		$message .= $Valid->ErrorMsg($params,'Company/company_created_month','required');
		$message .= $Valid->ErrorMsg($params,'Company/deputy_name','required');	
		$message .= $Valid->ErrorMsg($params,'Company/deputy_name','mbmaxlength','300');
		$message .= $Valid->ErrorMsg($params,'Company/employee_count','required');	
		$message .= $Valid->ErrorMsg($params,'Company/employee_count','maxlength','300');	
		$message .= $Valid->ErrorMsg($params,'Company/introduce','required');	
		$message .= $Valid->ErrorMsg($params,'Company/introduce','mbmaxlength','2000');
		$message .= $Valid->ErrorMsg($params,'Company/address','required');	
				
		$message .= $Valid->ErrorMsg($params,'Company/tel1','required');	
        $message .= $Valid->ErrorMsg($params,'Company/tel1','maxlength','300');
        $message .= $Valid->ErrorMsg($params,'Company/tel2','maxlength','300');
		$message .= $Valid->ErrorMsg($params,'Company/email','required');
		$message .= $Valid->ErrorMsg($params,'Company/email','mbmaxlength','100');		
		$message .= $Valid->ErrorMsg($params,'Company/email','confirm'); 
		$message .= $Valid->ErrorMsg($params,'Company/email','email');
		$message .= $Valid->ErrorMsg($params,'Company/email_confirm','required'); 	
		$message .= $Valid->ErrorMsg($params,'Company/incept_email','confirm');
		$message .= $Valid->ErrorMsg($params,'Company/url','url'); 
		$message .= $Valid->ErrorMsg($params,'Company/url','mbmaxlength',100); 				
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/name','required');					


		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','confirm'); 
		$message .= $Valid->ErrorMsg($params,'CompanyAccount/login_pwd','minmaxlength','6-20'); 
	
		$message .= $Valid->ErrorMsg($params,'Company/pwd_remain_id','required');	
		$message .= $Valid->ErrorMsg($params,'Company/pwd_remain_answer','required');			
		$message .= $Valid->ErrorMsg($params,'Company/pwd_remain_answer','mbminmaxlength','1-20'); 
					
		return $message;
	}
	function doDelete($id)
	{
		$sql="update company_info set deleted=now() where id in ($id)";
		$p=$this->query($sql);	
	}
	function delImage($companyid){
		$sql="update company_info set logo_name=null where id =$companyid";
		$this->query($sql);
	}
	function getComIdByName($name){
		$condition="(\"Company\".company_name like '%$name%' or \"Company\".company_alias like '%$name%') and \"Company\".deleted is null";
		$companies=$this->findAll($condition);
		$arr=array();
		foreach($companies as $company){
			$arr[]=$company['Company']['id'];
		}
		return implode(',',$arr);
	}
}
?>
